package cn.mugutu.finance.listener;

import cn.mugutu.finance.domain.system.Log;
import cn.mugutu.finance.listener.event.LogEvent;
import cn.mugutu.finance.service.system.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 系统日志记录监听器
 * @author ganbo E-mail:bo.gan@56qq.com
 * @since 2018-01-29 16:11
 */
@Component
public class LogRecordListener {

    @Autowired
    private LogService logService;

    /**.
     * 异步记录系统日志
     * @param logEvent
     */
    @Async
    @EventListener  //注册为一个监听器
    public void onApplicationEvent(LogEvent logEvent) {
        Log log = (Log) logEvent.getSource();
        logService.save(log);
    }
}
